{include file="public/header"}
<body>
<div id="app" v-cloak>
    <div class="ht-main">
        <div class="ht-main-body">
            <div class="ht-form">
                <el-form :model="editData" label-width="120px" size="small">
                    <el-form-item label="旧密码">
                        <el-input type="password" v-model="editData.old_password" placeholder="旧密码"></el-input>
                    </el-form-item>
                    <el-form-item label="新密码">
                        <el-input type="password" v-model="editData.password" placeholder="新密码"></el-input>
                    </el-form-item>
                    <el-form-item label="确认密码">
                        <el-input type="password" v-model="editData.password_confirm" placeholder="确认密码"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">提交</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</div>
{include file="public/common"}
<script>
    let vs ;
    new Vue({
        el: "#app",
        data: function () {
            return {
                showDialog: false,
                arctypeList: [],
                activeTab: 'first',
                tableData: [],
                is_edit: false,
                editData: {},
                editDataTemp: {},
                content: '编辑',
                total: 0,
                page: 1,
                limit: 10,
                shopList: [],
                agentList: [],
                archivesList: [],
                phpList:[],
                fileManage:false,
                hand_show:false,
                shop_id:''
            }
        },
        created: function () {
            vs = this;
            vs.getArchives();
            vs.getAgent();
            vs.getShop();
            vs.getData()
        },
        methods: {
            export1() {
                window.open("{:url('consumer/export')}")
            },
            doHand() {
                let ids = []
                console.log(vs.tableSelect)
                vs.tableSelect.map((item)=>{
                    ids.push(item.id)
                })
                $.post("{:url('consumer/hand')}",{ids:ids,shop_id:vs.shop_id},function (res) {
                    if (res.code == 1) {
                        vs.showSuccessMsgCall(()=>{
                            vs.getData()
                            vs.hand_show = false
                        })
                    } else {
                        vs.showErrorMsg(res.msg)
                    }
                })
            },
            hand() {
                vs.hand_show = true;
            },
            auto() {
                vs.confirm("自动分配将所有未分配的用户,随机均分给所有经销店,确定操作?",()=>{
                    $.post("{:url('consumer/auto')}",function (res) {
                        if (res.code == 1) {
                            vs.showSuccessMsgCall(()=>{
                                vs.getData()
                            })
                        } else {
                            vs.showErrorMsg(res.msg)
                        }
                    })
                })
            },
            getArchives() {
                vs.search_key = {}
                $.post("{:url('archives/all')}",{search_key:vs.search_key},function (res) {
                    if (res.code == 1) {
                        vs.archivesList = res.data
                    }
                })
            },
            getAgent() {
                vs.search_key = {}
                $.post("{:url('Agent/all')}",{search_key:vs.search_key},function (res) {
                    if (res.code == 1) {
                        vs.agentList = res.data
                    }
                })
            },
            getShop() {
                vs.search_key = {}
                $.post("{:url('shop/all')}",{search_key:vs.search_key},function (res) {
                    if (res.code == 1) {
                        vs.shopList = res.data
                    }
                })
            },
            imageManageClose(path) {
                this.showDialog = false;
            },
            imageSubmit(path) {
                console.log("path", path)
                this.editDataTemp.litpic = path[0]
                this.editData.litpic = path[0]
                this.showDialog = false;
            },
            imageManage() {
                this.showDialog = true;
            },
            uploadSuccess(litpic, value) {
                this.editDataTemp.litpic = litpic
                this.editData.litpic = litpic
            },

            changeStatus: function (e, id) {
                axios.post("{:url('Archives/ArchivesStatus')}", {id: id}).then((res) => {
                    if (res.data.code == 1) {
                        this.$message({
                            message: '操作成功',
                            type: 'success',
                            duration: 1000,
                        })
                    } else {
                        this.$message({
                            message: res.data.msg,
                            type: 'error',
                            duration: 1500,
                            onClose: function () {
                                location.reload()
                            }
                        })
                    }
                })
            },
            changeMenuStatus: function (e, id) {
                axios.post("{:url('Auth/menuStatus')}", {id: id}).then((res) => {
                    if (res.data.code == 1) {
                        this.$message({
                            message: '操作成功',
                            type: 'success',
                            duration: 1000,
                        })
                    } else {
                        this.$message({
                            message: res.data.msg,
                            type: 'error',
                            duration: 1500,
                            onClose: function () {
                                location.reload()
                            }
                        })
                    }
                })
            },
            onSubmit() {
                var that = this
                if (vs.editData.password !== vs.editData.password_confirm) {
                    that.showErrorMsg('密码和确认密码不一致')
                    return
                }
                $.post("{:url('Index/password')}", that.editData, function (res) {
                    if (res.code == 1) {
                        that.showSuccessMsgCall(function () {
                            that.is_edit = false;
                            that.editData = {};
                            that.getData()
                            that.getCategory()
                        })
                    } else {
                        that.showErrorMsg(res.msg)
                    }
                })
            },

            getData: function () {
                var that = this
                that.searchType = {
                    title: 'like'
                };
                $.post(index_url, {
                    limit: that.limit,
                    page: that.page,
                    search_key: that.searchKey,
                    search_type: that.searchType
                }, function (res) {
                    if (res.code == 1) {
                        that.tableData = res.data.data
                        that.total = res.data.total
                    } else {
                        that.showErrorMsg(res.msg)
                    }
                })
            },
            doAdd: function () {
                this.is_edit = true
                this.content = '添加'
                this.editData = {}
            },
            edit: function (data) {
                this.is_edit = true
                this.content = '编辑'
                this.editData = data

                console.log(data)
            },
            goBack: function () {
                this.is_edit = false
                vs.hand_show = false
            },
            del: function (data) {
                var that = this
                that.$confirm('确定删除么?', '提示', {
                    type: 'warning',
                    lockScroll: false
                }).then(() => {
                    $.post(del_url, {id: data.id}, function (res) {
                        if (res.code == 1) {
                            that.showSuccessMsgCall(function () {
                                that.getData()
                                that.getCategory()
                            })
                        } else {
                            that.showErrorMsg(res.msg)
                        }
                    })
                })
            },
            handleSizeChange: function (e) {
                this.limit = e
            },
            handleCurrentChange: function (e) {
                this.page = e
            }
        },
        watch: {
            page(v) {
                this.getData()
            },
            limit() {
                this.getData()
            }
        }
    })
</script>
</body>
</html>
